from machine import *
from global_var import *
from All_Init import *
import global_var
from motor import *
from Image import *
import Image
def Gyro_Data():
    lcd.str16(50, 50, f"Acc_x = {global_var.Gyro['ax']:.2f}",0xffff)
    lcd.str16(50, 70, f"Acc_y = {global_var.Gyro['ay']:.2f}",0xffff)
    lcd.str16(50, 90, f"Acc_z = {global_var.Gyro['az']:.2f}",0xffff)
    lcd.str16(50, 110, f"Gryo_x = {global_var.Gyro['gx']:.2f}",0xffff)
    lcd.str16(50, 130, f"Gryo_y = {global_var.Gyro['gy']:.2f}",0xffff)
    lcd.str16(50, 150, f"Gryo_z = {global_var.Gyro['gz']:.2f}",0xffff)
    lcd.str16(50, 170, f"Gx_bias = {global_var.Gyro['gx_bias']:.2f}",0xffff)
    lcd.str16(50, 190, f"Gy_bias = {global_var.Gyro['gy_bias']:.2f}",0xffff)
    lcd.str16(50, 210, f"Gz_bias = {global_var.Gyro['gz_bias']:.2f}",0xffff)
    lcd.str16(50, 230, f"Cal_Angle = {global_var.Cal_Angle:.2f}",0xffff)

def encoder_Data():
    lcd.str16(50, 230, f"Encoder_L = {global_var.Speed_L:.2f}",0xffff)
    lcd.str16(50, 250, f"Encoder_R = {global_var.Speed_R:.2f}",0xffff)
def PID_Data():
    lcd.str16(50, 50, f"Acc_Out = {Acc_PID.Output:.2f}",0xffff)
    lcd.str16(50, 70, f"Acc_p = {Acc_PID.Kp:.2f}",0xffff)
    lcd.str16(50, 90, f"Acc_d = {Acc_PID.Kd:.2f}",0xffff)
    lcd.str16(50, 110, f"Angle_Out = {Angle_PID.Output:.2f}",0xffff)
    lcd.str16(50, 130, f"Speed_Out = {Speed_PID.Output:.2f}",0xffff)
    lcd.str16(50, 150, f"Acc_Out = {Acc_Turn_PID.Output:.2f}",0xffff)
    lcd.str16(50, 170, f"Turn_Out = {Turn_PID.Output:.2f}",0xffff)
def Button_Event():
    global Direct_Up
    global Direct_Down
    global Direct_Right
    global Direct_Left
    global Direct_Center
    global Button1
    
    global_var.up_flag = 0
    global_var.down_flag = 0
    global_var.left_flag = 0
    global_var.right_flag = 0
    global_var.mid_flag = 0
    global_var.button1_flag = 0
    
    if Direct_Up.value() == 0:
        time.sleep_ms(80)
        if(Direct_Up.value() == 0):
            global_var.up_flag = 1
            
         
    if Direct_Down.value() == 0:
        time.sleep_ms(80)
        if Direct_Down.value() == 0:
            global_var.down_flag = 1

    if Direct_Right.value() == 0:
        time.sleep_ms(80)
        if Direct_Right.value() == 0:
            global_var.right_flag = 1

    if Direct_Left.value() == 0:
        time.sleep_ms(80)
        if Direct_Left.value() == 0:
            global_var.left_flag = 1               

    if Direct_Center.value() == 0:
        time.sleep_ms(80)
        if Direct_Center.value() == 0:
            global_var.mid_flag = 1               

    if Button1.value() == 0:
        time.sleep_ms(80)
        if(Button1.value() == 0):
            global_var.button1_flag = 1